package com.ruoyi.teach.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.teach.domain.TeachBookUser;
import com.ruoyi.teach.service.ITeachBookUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参与人Controller
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Api("参与人管理")
@RestController
@RequestMapping("/teach/user")
public class TeachBookUserController extends BaseController
{
    @Autowired
    private ITeachBookUserService teachBookUserService;

    /**
     * 查询参与人列表
     */
    @ApiOperation("查询参与人列表")   
    @PreAuthorize("@ss.hasPermi('teach:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachBookUser teachBookUser)
    {
        startPage();
        List<TeachBookUser> list = teachBookUserService.selectTeachBookUserList(teachBookUser);
        return getDataTable(list);
    }

    /**
     * 导出参与人列表
     */
    @ApiOperation("导出参与人列表")    
    @PreAuthorize("@ss.hasPermi('teach:user:export')")
    @Log(title = "参与人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TeachBookUser teachBookUser)
    {
        List<TeachBookUser> list = teachBookUserService.selectTeachBookUserList(teachBookUser);
        ExcelUtil<TeachBookUser> util = new ExcelUtil<TeachBookUser>(TeachBookUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取参与人详细信息
     */
    @ApiOperation("获取参与人详细信息")
    @ApiImplicitParam(name = "id", value = "参与人ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('teach:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(teachBookUserService.selectTeachBookUserById(id));
    }

    /**
     * 新增参与人
     */
    @ApiOperation("新增参与人")
    @PreAuthorize("@ss.hasPermi('teach:user:add')")
    @Log(title = "参与人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachBookUser teachBookUser)
    {
        return toAjax(teachBookUserService.insertTeachBookUser(teachBookUser));
    }

    /**
     * 修改参与人
     */
    @ApiOperation("修改参与人")  
    @PreAuthorize("@ss.hasPermi('teach:user:edit')")
    @Log(title = "参与人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachBookUser teachBookUser)
    {
        return toAjax(teachBookUserService.updateTeachBookUser(teachBookUser));
    }

    /**
     * 删除参与人
     */
    @ApiOperation("删除参与人")
    @ApiImplicitParam(name = "id", value = "参与人ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('teach:user:remove')")
    @Log(title = "参与人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teachBookUserService.deleteTeachBookUserByIds(ids));
    }
}
